<template>
    <div>
<<<<<<< HEAD
        门禁控制
=======
        <div style="width: 50%;margin: 20px 10px 10px 10px">
            <el-card class="box-card">
                <div slot="header" class="clearfix">
                    <span>下发命令，在下方选择好通道，再点击按钮</span><br>
                </div>
                <div class="text item">
                    <el-button size="small" type="primary" @click="openDoor">开门</el-button>
                    <el-button size="small" type="primary" @click="closeDoor">关门</el-button>
                    <el-button size="small" type="primary" @click="stayOpen">常开</el-button>
                    <el-button size="small" type="primary" @click="stayClose">常闭</el-button>
                    <el-button size="small" type="primary" @click="setNormal">设置门禁控制正常</el-button>
                </div>
            </el-card>
        </div>
        <div style="width: 80%;margin: 20px 10px 10px 10px">
            <el-table
                    :data="channelsData"
                    @selection-change="handleSelectionChange"
                    border
                    stripe
                    fit="true">
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>
                <el-table-column
                        prop="channelId"
                        label="通道编码"
                        width="180">
                </el-table-column>
                <el-table-column
                        prop="channelName"
                        label="通道名称"
                        width="180">
                </el-table-column>
                <el-table-column
                        prop="status"
                        label="通道状态 1/开门;2/关门;3/常开;4/常闭;5/正常"
                        width="180"
                        :filters="[{ text: '家', value: '家' }, { text: '公司', value: '公司' }]">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.status == 1" type="success">开门</el-tag>
                        <el-tag v-else-if="scope.row.status == 2" type="info">关门</el-tag>
                        <el-tag v-else-if="scope.row.status == 3" type="warning">常开</el-tag>
                        <el-tag v-else-if="scope.row.status == 4" type="danger">常闭</el-tag>
                        <el-tag v-else-if="scope.row.status == 5">正常</el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="deviceName"
                        label="设备名称"
                        width="180">
                </el-table-column>
                <el-table-column
                        prop="deviceId"
                        label="设备编码"
                        width="180">
                </el-table-column>
            </el-table>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[100, 200, 300, 400]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>
>>>>>>> 9bd91f7cdea89e78ee433b17f8909db13645484f
    </div>
</template>

<script>
<<<<<<< HEAD
  export default {
    name: 'ChannelControl'
=======
  import {getAllChannels, openDoor, closeDoor, stayOpen, stayClose, setNormal} from '@/api/channelcontrol'

  export default {
    name: 'ChannelControl',
    data(){
      return {
        channelsData: [],
        channelCodeList: [],
        multipleSelection: [],
        total: 0,
        pageSize: 100,
        currentPage: 1
      }
    },
    created() {
      this.initChannels()
    },
    methods: {
      initChannels(){
        let query = {
          currentPage: this.currentPage,
          pageSize: this.pageSize
        }
        getAllChannels(query).then(resp => {
           if(resp){
             this.channelsData = resp.data
             // this.total = resp.pagination.recordsCount
             this.total = this.channelsData.length
           }
        })
      },
      handleSelectionChange(rows){
        this.multipleSelection = rows
      },
      openDoor(){
        this.multipleSelection.forEach(item => {
          this.channelCodeList.push(item.channelId)
        })
        openDoor(this.channelCodeList).then(resp => {
            if(resp){
              this.$message({
                message: '开门消息发送成功',
                type: 'success'
              });
              this.multipleSelection = []
              this.channelCodeList = []
              this.initChannels()
            }
        })
      },
      closeDoor(){
        this.multipleSelection.forEach(item => {
          this.channelCodeList.push(item.channelId)
        })
        closeDoor(this.channelCodeList).then(resp => {
          if(resp){
            this.$message({
              message: '关门消息发送成功',
              type: 'success'
            });
            this.multipleSelection = []
            this.channelCodeList = []
            this.initChannels()
          }
        })
      },
      stayOpen(){
        this.multipleSelection.forEach(item => {
          this.channelCodeList.push(item.channelId)
        })
        stayOpen(this.channelCodeList).then(resp => {
          if(resp){
            this.$message({
              message: '常开消息发送成功',
              type: 'success'
            });
            this.multipleSelection = []
            this.channelCodeList = []
            this.initChannels()
          }
        })
      },
      stayClose(){
        this.multipleSelection.forEach(item => {
          this.channelCodeList.push(item.channelId)
        })
        stayClose(this.channelCodeList).then(resp => {
          if(resp){
            this.$message({
              message: '常关消息发送成功',
              type: 'success'
            });
            this.multipleSelection = []
            this.channelCodeList = []
            this.initChannels()
          }
        })
      },
      setNormal(){
        this.multipleSelection.forEach(item => {
          this.channelCodeList.push(item.channelId)
        })
        setNormal(this.channelCodeList).then(resp => {
          if(resp){
            this.$message({
              message: '门通道模式设置为正常',
              type: 'success'
            });
            this.multipleSelection = []
            this.channelCodeList = []
            this.initChannels()
          }
        })
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.currentPage = val
      }
    }
>>>>>>> 9bd91f7cdea89e78ee433b17f8909db13645484f
  }
</script>

<style scoped>

</style>
